/*
 * @Author: lp
 * @Date: 2022-01-11 15:24:12
 * @LastEditTime: 2022-06-25 16:38:33
 * @LastEditors: 瞿旺兴 18774621495@163.com
 * @Description: 路由入口
 */
import { createWebHistory, createRouter } from 'vue-router'
import navigationGuard from './navigationGuard'
import userStore from '@/store/modules/user' 
import { queryRedirect } from '@/utils'

const Layout = () => import('@/layout/index.vue')

//  定义固定路由
export const routes: any = [
  // { path: "/", component: () => import(/* webpackChunkName: "app-index" */ "@/views/index.vue") },
  {
    path: '/',
    component: Layout,
    redirect: 'index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/index/index.vue'),
        name: 'index',
        meta: { title: '首页', icon: 'dashboard', noCache: true, affix: true },
      },
    ],
  },
  {
    path: '/login',
    hidden: true,
    redirect: '/login/signIn',
    component: () => import(/* webpackChunkName: "login" */ '@/views/login.vue'),
    children: [
      {
        path: 'signIn',
        component: () => import('@/views/signIn.vue'),
      },
      {
        path: 'resetPswd',
        name: 'resetPswd',
        component: () => import('@/views/resetPswd.vue'),
      },
      {
        path: 'selectCompany',
        name: 'selectCompany',
        component: () => import('@/views/selectCompany.vue'),
        beforeEnter: () => {
          const user = userStore()  
          if (user.company) {
            return { path: queryRedirect().value || '/' }
          }
          return true
        },
      },
    ],
  },
  { path: '/redirect/:path*', component: () => import('@/views/redirect.vue') },
	
  {
    path: '/dict',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'type/data/:dictId(\\d+)',
        component: () => import('@/views/system/dict/data.vue'),
        name: 'Data',
        meta: { title: '字典数据', icon: '' },
      },
    ],
  },
  {
    path: '/:path(.*)*',
    component: Layout,
    children: [{
      path: '',
      component: () => import('@/views/404.vue'),
    }],
    hidden: true,
  },
  {
    path: '/monitor/log',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/monitor/job/log.vue'),
        name: 'JobLog',
        meta: { title: '调度日志', activeMenu: '/monitor/job' },
      },
    ],
  },
  // 财务详情页
  {
    path: '/finace',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'airSeaExpress/detail/:serialNo',
        component: () => import('@/views/finance/receiverManame/reconciliationManagement/Receivable/airSeaExpress/detail.vue'),
        name: 'AirSeaExpressDetail',
        meta: { title: '空海派-快递详情', icon: 'dashboard' },
      },
      {
        path: 'airSeaTransport/detail/:serialNo',
        component: () => import('@/views/finance/receiverManame/reconciliationManagement/Receivable/airSeaTransport/detail.vue'),
        name: 'AirSeaTransportDetail',
        meta: { title: '空海运详情', icon: 'dashboard' },
      },
      {
        path: 'endFinancial/detail',
        component: () => import('@/views/finance/receiverManame/endFinancial/detail.vue'),
        name: 'EndFinancialDetail',
        meta: { title: '末端财务详情', icon: 'dashboard' },
      },
      {
        path: 'airSeaDispatchWriteOff/detail',
        component: () => import('@/views/finance/receiverManame/collectionManager/airSeaDispatchWriteOff/detail.vue'),
        name: 'AirSeaDispatchWriteOffDetail',
        meta: { title: '空海派核销详情', icon: 'dashboard' },
      },
    ],
  },
  {
    path: "/businessConfig/orderException",
    hidden: true,
    component: Layout,
    children: [
      {
        name: "OrderException",
        component: () => import("@/views/index/orderException.vue"),
        path: "/orderException",
        meta: { title: "账单异常管理", icon: "" },
      },
    ],
  },
  {
    path: "/businessConfig/order",
    hidden: true,
    component: Layout,
    children: [
      {
        name: "Order",
        component: () => import("@/views/businessConfig/order/index.vue"),
        path: "/order",
        meta: { title: "预警通知", icon: "" },
      },
    ],
  },
]
//  创建路由实例并传递 `routes` 配置
const router = createRouter({
  //  history createWebHistory(base)
  history: createWebHistory('.'),
  routes, // `routes: routes` 的缩写
})
// 路由守卫
navigationGuard(router)
export default router
